package com.rongxue.utils;

import java.text.SimpleDateFormat;
import java.util.Base64;
import java.util.Date;
import java.util.Random;

/**
 * Created by g on 2017/8/7.
 */
public class RandomUtil {public static String getRandom(int c) {
    Random r = new Random();
    SimpleDateFormat format = new SimpleDateFormat("SSS");
    Date d = new Date();
    StringBuffer sb = new StringBuffer();
    sb.append(format.format(d));
    for (int i = sb.length(); i < c; i++) {
        sb.append(r.nextInt(10));
    }
    return sb.toString();
}

    public static String getSMSCODE() {
        int x = (int) (Math.random() * 9000 + 1000);
        return String.valueOf(x);
    }

    public static void main(String args[]) {
        Base64.Encoder  encoder= Base64.getEncoder();
        String str =1+"&"+2;
        System.out.println(str);
        byte[] e = encoder.encode(str.getBytes());
        String encode = new String(e);
        System.out.println(encode);

        Base64.Decoder decoder = Base64.getDecoder();
        byte[] tokens = decoder.decode(encode);
        String message = new String(tokens);
        System.out.println(message);
    }

    public static String genMobile() {
        StringBuffer sb = new StringBuffer();
        Random r = new Random();
        SimpleDateFormat format = new SimpleDateFormat("DDssSSS");
        Date d = new Date();
        sb.append("1");
        sb.append("3");
        sb.append(r.nextInt(10));
        sb.append(format.format(d));
        return sb.toString();
    }
}